﻿package {

	import flash.display.*;
	import flash.events.*;
	import flash.net.*;
	import flash.text.*;
	import flash.system.*;

	public class Open extends MovieClip {

		private var tw:Number;
		private var th:Number;
		
		public var file:FileReference;
		public var fileFilters:Array;
		public function Open() {
			stage.align = "TL";
			Security.allowDomain("*");
			file = new FileReference();
			fileFilters = getFilters();
			bt_open.addEventListener(MouseEvent.CLICK, openCLick);
		}
		
		
		private function openCLick(e:MouseEvent):void {
			file.browse(fileFilters);
			file.addEventListener(Event.SELECT, onFileSelected);
		}
		private function onFileSelected(e:Event):void {
			file.addEventListener(Event.COMPLETE, onFileLoaded);
			file.load();
		}

		private function onFileLoaded(e:Event):void {
			var loader:Loader = new Loader();
			loader.loadBytes(file.data);
			
			if (numChildren >= 2) {
				removeChildAt(0);
			}
			addChildAt(loader, 0);
			
		}
		
		
		private function getFilters():Array {
			var arr:Array = [new FileFilter("Images", "*.jpg;*.png;*.swf")];
			return arr;
		}
	}

}